// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

pub(crate) mod api;
#[macro_use]
pub(crate) mod conversion;
pub(crate) mod cache;
pub(crate) mod config;
mod commands;

use tauri::{Manager, Runtime};
use window_shadows::set_shadow;
use crate::commands::{refresh, get_indices, get_indices_aliases, get_indices_stats, get_indices_mapping, get_indices_settings, get_indices_stats_docs_store, action_add_aliases, action_delete_aliases, action_remove_indices, action_open_indices, action_close_indices, get_cat_indices, action_create_index, search, get_node, get_optional_node, set_node};


#[tokio::main]
async fn main() {

    config::init_config().await;

    tauri::Builder::default()
        .setup(|app| {
            set_window_shadow(app);
            Ok(())
        })
        .invoke_handler(tauri::generate_handler![get_node,get_optional_node,set_node,
            refresh,get_indices,get_cat_indices,
            get_indices_aliases,get_indices_stats,get_indices_mapping,
            get_indices_settings,get_indices_stats_docs_store,action_add_aliases,action_delete_aliases,
            action_close_indices,action_open_indices,action_remove_indices,action_create_index,
        search])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}


pub fn set_window_shadow<R: Runtime>(app: &tauri::App<R>) {
    let window = app.get_window("main").unwrap();
    #[cfg(any(windows, target_os = "macos"))]
    set_shadow(&window, true).expect("Unsupported platform!");
}